package org.hiucung.lib_network.interceptor

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @title: HttpInterceptor
 * @projectName OrangeAiVoiceApp
 * @description: HTTP拦截器
 * 比如我们需要输出网络请求和相应的日志，在没有拦截器的情况下每次都要打log非常冗余
 * 重定向
 * 统一请求头
 * 加密/解谜
 *
 * @author Kicc
 * @date 2021/11/25 17:51
 */
class HttpInterceptor: Interceptor {

    private val TAG = "HTTP"

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val response = chain.proceed(request)

        Log.i(TAG,"=================REQUEST================")
        if (request.method() == "GET"){
            Log.i(TAG,request.url().toString())
        }
        Log.i(TAG,"=================RESPONSE================")
        response.body()?.let {
            Log.i(TAG,it.string())
        }

        return response
    }
}